package com.origin.oss.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.origin.oss.enums.FileUploadStateEnum;
import lombok.Data;
import org.springframework.data.annotation.Id;

import java.time.LocalDateTime;

/**
 * 文件上传任务
 *
 * @author origin
 * @date 2024/2/5 13:07
 */
@TableName("file_upload_task")
@Data
public class FileUploadTask {

    @Id
    @TableId(value = "upload_task_id", type = IdType.AUTO)
    private Long uploadTaskId;

    /**
     * 上传状态, 1 - 成功, 0 - 失败, 2 - 未完成
     */
    @TableField("upload_state")
    private Integer uploadState;

    /**
     * file_info 表主键
     */
    @TableField("file_id")
    private String fileId;

    /**
     * 文件总分片数
     */
    @TableField("total_chunk")
    private Integer totalChunk;

    /**
     * 上传时间
     */
    @TableField("create_datetime")
    private LocalDateTime createDateTime;

    public static FileUploadTask init(String fileId, int totalChunk) {
        FileUploadTask fileUploadTask = new FileUploadTask();
        fileUploadTask.uploadState = FileUploadStateEnum.UNCOMPLETE.getCode();
        fileUploadTask.fileId = fileId;
        fileUploadTask.totalChunk = totalChunk;
        fileUploadTask.createDateTime = LocalDateTime.now();
        return fileUploadTask;
    }

}
